home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / validateShelfName.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.3 KB  |  113 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date:  Oct 1999
  22. //
  23. //
  24. //<doc>
  25. //<name validateShelfName>
  26. //<owner "Alias|Wavefront Unsupported">
  27. //
  28. //<synopsis>
  29. //        validateShelfName (string $newName)
  30. //
  31. //<returns>
  32. //        int : 1 if the name is valid, 0 otherwise
  33. //
  34. //<description>
  35. //        This script is called to make verify that a potential name
  36. //        for a shelf tab is valid.
  37. //
  38. //<flags>
  39. //        string $newName Potential shelf name to check.
  40. //
  41. //<examples>
  42. //    validateShelfName "123isNotValid";
  43. //
  44. //</doc>
  45.  
  46. global proc int validateShelfName (string $newName)
  47. {
  48.     int $isOkay = true;
  49.  
  50.     string $regex = "[^0-9a-zA-Z_]";
  51.     string $firstCharRegex = "[0-9]";
  52.     string $match = match( $regex, $newName );
  53.     
  54.     string $fileName = (`internalVar -userShelfDir` + "shelf_" + $newName + ".mel");
  55.  
  56.     //
  57.     // test for zero length
  58.     //
  59.     if (size($newName) == 0) {
  60.         confirmDialog -title "Alert" 
  61.             -button "OK" -defaultButton "OK"
  62.             -message "       Shelf name must be one or more characters long. Please enter a name.       ";
  63.         $isOkay = false;
  64.     //
  65.     // test for bad characters
  66.     //
  67.     } else if ($match != "") {
  68.         confirmDialog -title "Alert" 
  69.             -button "OK" -defaultButton "OK"
  70.             -message ("       Shelf name contains illegal characters. Please select another name.        \n"+
  71.                       "Valid names can contain only letters, numbers and underscores.");
  72.         $isOkay = false;
  73.     //
  74.     // test for bad first character
  75.     //
  76.     } else if ("" != match($firstCharRegex, `substring $newName 1 1`)) {
  77.         confirmDialog -title "Alert" 
  78.             -button "OK" -defaultButton "OK"
  79.             -message "       Shelf name cannot begin with a numeric character. Please select another name.        ";
  80.         $isOkay = false;
  81.     //
  82.     // test for existing saved shelves
  83.     //
  84.     } else if (`file -q -exists $fileName`) {
  85.         confirmDialog -title "Alert" 
  86.             -button "OK" -defaultButton "OK"
  87.             -message "       Shelf name is not unique. Please select another name.        ";
  88.         $isOkay = false;
  89.     } else {
  90.         //
  91.         //  test for existing shelves in optionVars
  92.         //
  93.         string $shelfName;
  94.         $nShelves = `optionVar -q numShelves`;
  95.         for ($i = 1; $i <= $nShelves; $i++) {
  96.             $varName = ("shelfName" + $i);
  97.             $shelfName = `optionVar -q $varName`;
  98.             if ($shelfName == $newName) {
  99.                 $isOkay = false;
  100.                 break;
  101.             }
  102.         }
  103.         
  104.         if (!$isOkay) {
  105.             confirmDialog -title "Alert" 
  106.                 -button "OK" -defaultButton "OK"
  107.                 -message "       Shelf name is not unique. Please select another name.        ";
  108.         }
  109.     }
  110.     
  111.     return $isOkay;
  112. }
  113.